<?php
/**
* This is the index.ctp
* @author Amissah Gideon<kuulmek@yahoo.com>
    * @access public
    * @version 1.0
    */

    $currentPage = $html->url(array('controller' => 'Questions', 'action' => 'index'));

    $start = $startRow_display + 1;
    ?>
    <div class="row " id="questions_ans_content" style=" <?php echo ($show_intro) ? 'display:none;' : 'display:block;' ;?>">
        <div class="span10 offset1" style="background-color: #ffffff; line-height: 8px;">
            <?php if($questions_set){
            ?>
            <div style="padding:30px; text-align: left; font-size: 24px; font-weight: bolder;"><?php echo $header; ?></div>
            <form action="" method="post" id="questions_form">
                <?php					
                $count = $start;
                $ques_ans = array();
                if($this->Session->check('QuesAns')){
                $ques_ans = $this->Session->read('QuesAns');
                }

                foreach($questions_set as $ques){
                $ans_type = $ques['Question']['type'];
                $ans_format = $ques['Question']['format'];
                $ques_id = $ques['Question']['id'];
                $question_group = $ques['Question']['question_group'];
                $user_ans_pool = null;
                if(isset($ques_ans[$question_group][$ques_id])){
                $user_ans_pool = $ques_ans[$question_group][$ques_id];
                }
                ?>
                <ul class="unstyled" style="margin-bottom: 20px;">
                    <li><p><?php echo $count.'.  '.$ques['Question']['question']; ?></p></li>
                    <li>
                        <ul style="list-style: none;">
                            <?php
                            foreach($ques['Answer'] as $ans){
                            $answer_id = $ans['id'];
                            $checked = '';
                            if($ans_type == 'checkbox'){
                            if($user_ans_pool != null && is_array($user_ans_pool)){
                            if(isset($user_ans_pool[$answer_id])){
                            $checked = "checked='checked'";
                            }
                            }
                            echo "<li style=''><p><input  type='checkbox' name='data[$ques_id][$answer_id]' value='$answer_id' $checked /> "." &nbsp;&nbsp;&nbsp;&nbsp;" .$ans['answer']."</p></li>";
                            }
                            else if($ans_type == 'radio'){
                            if($user_ans_pool != null ){
                            if($user_ans_pool == $answer_id){
                            $checked = "checked='checked'";
                            }
                            }
                            echo "<li style=''><p><input type='radio' name='data[$ques_id]' value='$answer_id' $checked /> "." &nbsp;&nbsp;&nbsp;&nbsp;" .$ans['answer']."</p></li>";
                            }
                            else if($ans_type == 'textbox'){
                            echo "<li style=''><p><input type='text' name='data[$ques_id]' value='$user_ans_pool' /></p></li>";
                            }
                            }
                            if(count($ques['Answer']) < 1){
                            if($ans_type == 'textbox'){
                            echo "<li style=''><p><input type='text' name='data[$ques_id]' value='$user_ans_pool' /></p></li>";
                            }
                            }
                            ?>
                        </ul>
                    </li>
                </ul>
                <?php
                $count++;
                }
                ?>
            </form>

            <!-- Pagination Links Url -->
            <input type='hidden' id="paginate_first" value="<?php printf("%s?pageNum_display=%d%s", $currentPage, 0, $queryString_display); ?>" />
                   <input type='hidden' id="paginate_previous" value="<?php printf("%s?pageNum_display=%d%s", $currentPage, max(0, $pageNum_display - 1), $queryString_display); ?>" />
                   <input type='hidden' id="paginate_next" value="<?php printf("%s?pageNum_display=%d%s", $currentPage, min($totalPages_display, $pageNum_display + 1), $queryString_display); ?>" />
                   <input type='hidden' id="paginate_last" value="<?php printf("%s?pageNum_display=%d%s", $currentPage, $totalPages_display, $queryString_display); ?>" />
                   <input type='hidden' id="paginate_finish" value="<?php echo $currentPage.'?'.'finish=finish'; ?>" />
            <input type='hidden' id="paginate_nextQuesSet" value="<?php echo $currentPage.'?'.'nextQuesSet=yes'.'&'.'pageNum_display=0'; ?>" />
            <!-- End of Pagination Links Url -->

            <ul class="pager">
                <li class="previous" style="line-height: 18px;">
                    <?php if ($pageNum_display > 0) { // Show if not first page ?>
                    <a href="javascript:void(0);" data-url="paginate_previous">&larr; Previous</a>
                    <?php } // Show if not first page ?>
                </li>
                <li class="next" style="line-height: 18px;">
                    <?php if ($pageNum_display < $totalPages_display) { // Show if not last page ?>
                    <a href="javascript:void(0);" data-url="paginate_next">Save and Continue &rarr;</a>
                    <?php }
                    else{
                    if($continue){
                    ?>
                    <a href="javascript:void(0);" data-url="paginate_nextQuesSet">Save And Proceed To The Next Section &rarr;</a>
                    <?php
                    }
                    else{
                    ?>
                    <a href="javascript:void(0);" data-url="paginate_finish">Finish</a>
                    <?php
                    }
                    ?>

                    <?php
                    }
                    ?> 
                </li>
            </ul>

            <?php 
            }
            else{
            echo __('<h1>Sorry no quetions at this time</h1>',true);
            }	
            ?>

        </div>
    </div>

    <div class="row " id="intro_message" style="<?php echo ($show_intro) ? 'display:block;' : 'display:none;' ;?>">
        <div id="" class="span10 offset1" style="line-height: 8px; padding: 20px; ">
            <?php
            if ($ques_group_type == 'p') {
            ?>
            <div>
                <div style="text-align: center; padding-top: 40px; padding-bottom: 50px;">
                    <div class="header">
                        Section A: People Factor
                    </div><br/><br/><br/>
                    <div class="imgs">
                        <?php echo $this->Html->image('people.png', array( 'border' => '0','width'=>800,'height'=>400)) ?>
                    </div>
                    <br/><br/><br/>

                    <div style="padding-left: 20px; padding-top: 40px;">
                        <span style="float: left; font-family: Verdana; font-size: 16px;"> <strong>Estimated Section Completion Time:</strong> 25-30 minutes</span>
                        <span style="float: left; padding-left: 170px;"><h3><a href="javascript:void(0);" class="intro_message_btn">Continue with PACEM Test >></a></h3></span>
                    </div>
                </div>
            </div>

            <?php
            }
            else if ($ques_group_type == 'sys') {
            ?>
            <div>
                <div style="text-align: center; padding-top: 40px; padding-bottom: 50px;">
                    <div class="header">
                        Section B: System Factor
                    </div><br/><br/><br/>
                    <div class="imgs">
                        <?php echo $this->Html->image('system.png', array( 'border' => '0','width'=>800,'height'=>400)) ?>
                    </div>
                    <br/><br/><br/>

                    <div style="padding-left: 20px; padding-top: 40px;">
                        <span style="float: left; font-family: Verdana; font-size: 16px;"> <strong>Estimated Section Completion Time:</strong> 10-15 minutes</span>
                        <span style="float: left; padding-left: 170px;"><h3><a href="javascript:void(0);" class="intro_message_btn">Continue with PACEM Test >></a></h3></span>
                    </div>
                </div>
            </div>
            <?php
            }
            else if ($ques_group_type == 'str') {
            ?>
            <div>
                <div style="text-align: center; padding-top: 40px; padding-bottom: 50px;">
                    <div class="header">
                        Section  C: Strategy Factor
                    </div><br/><br/><br/>
                    <div class="imgs">
                        <?php echo $this->Html->image('strategy.png', array( 'border' => '0','width'=>800,'height'=>400)) ?>
                    </div>

                    <br/><br/><br/>
                    <div style="padding-left: 20px; padding-top: 40px;">
                        <span style="float: left; font-family: Verdana; font-size: 16px;"> <strong>Estimated Section Completion Time:</strong> 10-15 minutes</span>
                        <span style="float: left; padding-left: 170px;"><h3><a href="javascript:void(0);" class="intro_message_btn">Continue with PACEM Test >></a></h3></span>
                    </div>
                </div>
            </div>
            <?php
            }
            ?>


        </div>
    </div>

    <script type="text/javascript">
    $(document).ready(function() {
        $("ul.pager > li > a").click(function(){
            var hidden = $(this).attr('data-url');
            var action = $("#"+hidden+"").val();
            $("#questions_form").attr('action',action).submit();
        });

        $("a.intro_message_btn").click(function(){
            $("#intro_message").hide();
            $("#questions_ans_content").show();
        });
    });
    </script>

    <style type="text/css">
        .cot{
            -moz-border-radius:3px;
            border-radius: 3px;
            -webkit-border-radius: 3px;
            -webkit-box-shadow:inset 0 2px 2px 0;
            -moz-box-shadow:inset 0 2px 2px 0 #374e65;
            width: 450px;

            margin-left: 400px;
            font-family: Century Gothic;
            padding: 10px;
            font-size: 18px;
        }

        .header{
            font-family: Verdana;
            font-size: 40px;
            font-weight: bold;
        }
        .imgs{

        }
    </style>